#ifndef SERVER_H
#define SERVER_H

#include <QThread>
#include <QTcpServer>
#include <QTcpSocket>
#include <QList>
#include "Networking/session.h"
#include "Bonjour/bonjourregister.h"

class Server : public QThread
{
Q_OBJECT

public:
	Server(QString newName, int newPort, Session *currSesssion);
	~Server();

	void run();

signals:
	void showMessageBox(int ico, QString message);

private slots:
	void handleBonjourError();
	void handleNewConnection();
	void receiveMessage();

private:
	QByteArray packageMessage(QByteArray bytes);	//packages a message with the size for ease of sending
	void sendToAll(QByteArray msg);		//sends msg to all clients
	void processMessage(QByteArray msg);	//processes a recieved message

	QString name;
	int port;
	QTcpServer *sock;
	QList<QTcpSocket*> connections;
	BonjourRegister *bonjour;	//the bonjour registration object

	Session *session;
};

#endif // SERVER_H
